home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / site-packages / psyco / kdictproxy.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2006-03-29  |  5KB  |  180 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. from __future__ import generators
  5.  
  6. try:
  7.     from UserDict import DictMixin
  8. except ImportError:
  9.     
  10.     class DictMixin:
  11.         
  12.         def __iter__(self):
  13.             for k in self.keys():
  14.                 yield k
  15.             
  16.  
  17.         
  18.         def has_key(self, key):
  19.             
  20.             try:
  21.                 value = self[key]
  22.             except KeyError:
  23.                 return False
  24.  
  25.             return True
  26.  
  27.         
  28.         def __contains__(self, key):
  29.             return self.has_key(key)
  30.  
  31.         
  32.         def iteritems(self):
  33.             for k in self:
  34.                 yield (k, self[k])
  35.             
  36.  
  37.         
  38.         def iterkeys(self):
  39.             return self.__iter__()
  40.  
  41.         
  42.         def itervalues(self):
  43.             for _, v in self.iteritems():
  44.                 yield v
  45.             
  46.  
  47.         
  48.         def values(self):
  49.             return [ v for _, v in self.iteritems() ]
  50.  
  51.         
  52.         def items(self):
  53.             return list(self.iteritems())
  54.  
  55.         
  56.         def clear(self):
  57.             for key in self.keys():
  58.                 del self[key]
  59.             
  60.  
  61.         
  62.         def setdefault(self, key, default):
  63.             
  64.             try:
  65.                 return self[key]
  66.             except KeyError:
  67.                 self[key] = default
  68.  
  69.             return default
  70.  
  71.         
  72.         def pop(self, key, *args):
  73.             if len(args) > 1:
  74.                 raise TypeError, 'pop expected at most 2 arguments, got ' + repr(1 + len(args))
  75.             
  76.             
  77.             try:
  78.                 value = self[key]
  79.             except KeyError:
  80.                 if args:
  81.                     return args[0]
  82.                 
  83.                 raise 
  84.  
  85.             del self[key]
  86.             return value
  87.  
  88.         
  89.         def popitem(self):
  90.             
  91.             try:
  92.                 (k, v) = self.iteritems().next()
  93.             except StopIteration:
  94.                 raise KeyError, 'container is empty'
  95.  
  96.             del self[k]
  97.             return (k, v)
  98.  
  99.         
  100.         def update(self, other):
  101.             if hasattr(other, 'iteritems'):
  102.                 for k, v in other.iteritems():
  103.                     self[k] = v
  104.                 
  105.             elif hasattr(other, '__iter__'):
  106.                 for k in other:
  107.                     self[k] = other[k]
  108.                 
  109.             else:
  110.                 for k in other.keys():
  111.                     self[k] = other[k]
  112.                 
  113.  
  114.         
  115.         def get(self, key, default = None):
  116.             
  117.             try:
  118.                 return self[key]
  119.             except KeyError:
  120.                 return default
  121.  
  122.  
  123.         
  124.         def __repr__(self):
  125.             return repr(dict(self.iteritems()))
  126.  
  127.         
  128.         def __cmp__(self, other):
  129.             if other is None:
  130.                 return 1
  131.             
  132.             if isinstance(other, DictMixin):
  133.                 other = dict(other.iteritems())
  134.             
  135.             return cmp(dict(self.iteritems()), other)
  136.  
  137.         
  138.         def __len__(self):
  139.             return len(self.keys())
  140.  
  141.  
  142.  
  143. from _psyco import compact
  144.  
  145. class compactdictproxy(DictMixin):
  146.     
  147.     def __init__(self, ko):
  148.         self._ko = ko
  149.  
  150.     
  151.     def __getitem__(self, key):
  152.         return compact.__getslot__(self._ko, key)
  153.  
  154.     
  155.     def __setitem__(self, key, value):
  156.         compact.__setslot__(self._ko, key, value)
  157.  
  158.     
  159.     def __delitem__(self, key):
  160.         compact.__delslot__(self._ko, key)
  161.  
  162.     
  163.     def keys(self):
  164.         return compact.__members__.__get__(self._ko)
  165.  
  166.     
  167.     def clear(self):
  168.         keys = self.keys()
  169.         keys.reverse()
  170.         for key in keys:
  171.             del self[key]
  172.         
  173.  
  174.     
  175.     def __repr__(self):
  176.         keys = ', '.join(self.keys())
  177.         return '<compactdictproxy object {%s}>' % (keys,)
  178.  
  179.  
  180.